using System;
using System.Collections.Generic;

namespace LannyPractiseCode
{
    //表示链表
    public class MyHashTable
    {
        private int size;
        private EmployeeLinkedList[] employeeLinkedLists;
        public MyHashTable(int size)
        {
            this.size=size;
            employeeLinkedLists=new EmployeeLinkedList[size];

            for (int i = 0; i < size; i++)
            {
                employeeLinkedLists[i]=new EmployeeLinkedList();
            }
        }

        public void Add(Employee employee)
        {
            //根据员工Id，查看员工属于哪条链表
            int empLinkedListNo=HashFun(employee.Id);
            employeeLinkedLists[empLinkedListNo].Add(employee);
        }

        public void FindEmplyeeByID(int id)
        {
            int empLinkedListNo=HashFun(id);
            System.Console.WriteLine($"****{empLinkedListNo}");
            Employee employee= employeeLinkedLists[empLinkedListNo].FindEmplyeeByID(id);
            if(employee!=null)
                System.Console.WriteLine($"在{empLinkedListNo+1}条链条找到信息");
            else
                System.Console.WriteLine("没找到信息。。");
        }
        public void Display()
        {
            for (int i = 0; i < size; i++)
            {
                employeeLinkedLists[i].Display(i);
            }
        }

        //散列函数，使用取模法
        public int HashFun(int id)
        {
            return id %size;
        }
    }
}